package com.lan.evalulate;


import com.lan.model.symbol.*;
import com.lan.script.BlockOt;
import com.lan.script.FunctionOt;
import com.lan.script.JsonOt;
import com.lan.script.ScriptOt;

public class StackFrame {

    private Scope scope;

    private StackFrame parent;

    private ScriptOt object;

    public StackFrame(Block scope) {
        this.scope = scope;
        this.object = new BlockOt(scope);
    }

    public StackFrame(FunctionOt object) {
        this.scope = object.getFunction();
        this.object = object;
    }


    public StackFrame(JsonOt object) {
        this.scope = object.getJson();
        this.object = object;
    }

    public boolean contains(Variable variable) {
        if (object != null && object.getMetadata() != null) {
            return object.getMetadata().containsKey(variable);
        }
        return false;
    }

    public Scope getScope() {
        return scope;
    }

    public void setScope(Scope scope) {
        this.scope = scope;
    }

    public StackFrame getParent() {
        return parent;
    }

    public void setParent(StackFrame parent) {
        this.parent = parent;
    }

    public ScriptOt getObject() {
        return object;
    }

    public void setObject(ScriptOt object) {
        this.object = object;
    }

    @Override
    public String toString() {
        String rtn = "" + scope;
        if (parent != null) {
            rtn += " -> " + parent;
        }
        return rtn;
    }

}
